package com.zlj.request;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 防盗链：如果请求不是通过本站的链接发出的，则进行相应的处理
 * 
 * Referer请求头：表示请求的来源
 */
@WebServlet("/RequestCServlet")
public class RequestCServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
   
	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		/*
		 * 使用Referer请求头来防盗链
		 */
		String header = request.getHeader("Referer");
		System.out.println(header);
		
		if(header == null || !header.contains("localhost")){
			response.sendRedirect("http://www.baidu.com");
		}else{
			System.out.println("hello");
		}
	}
}
